<!--
 * @Author: 89-83-77
 * @Description: 登录页
 * @Date: 2025-03-27 17:00:36
 * @LastEditTime: 2025-03-29 17:56:47
 * @FilePath: \fz-yzt-webd:\work\client\src\views\login\login.vue
-->
<template>
    <div class="login-container">
        <el-card class="login-box">
            <h2 class="title">{{ systemName }}</h2>
            <el-form :model="form" :rules="rules" ref="loginForm" @keyup.enter="handleLogin">
                <el-form-item prop="username">
                    <el-input v-model="form.username" prefix-icon="User" placeholder="用户名" class="custom-input" />
                </el-form-item>
                <el-form-item prop="password">
                    <el-input v-model="form.password" :type="showPassword ? 'text' : 'password'" placeholder="密码"
                        class="custom-input">
                        <template #prefix>
                            <el-icon>
                                <Lock />
                            </el-icon>
                        </template>
                        <template #suffix>
                            <el-icon class="password-eye" :color="showPassword ? '#409eff' : '#c0c4cc'"
                                @click="showPassword = !showPassword">
                                <Component :is="showPassword ? View : Hide" />
                            </el-icon>
                        </template>
                    </el-input>
                </el-form-item>
                <el-button type="primary" @click="handleLogin" :loading="loading" class="login-btn">
                    登录
                </el-button>
            </el-form>
        </el-card>
    </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { Lock, Hide, View } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import { useUserStore } from '@/stores/user.js'

const router = useRouter()
const userStore = useUserStore()
const loading = ref(false)
const showPassword = ref(false)
const systemName = ref(import.meta.env.VITE_BASE_TITLE || '事件分析管理系统') // 系统名称
const form = ref({
    username: '',
    password: ''
})

const rules = {
    username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
    password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
}

const handleLogin = async () => {
    try {
        // 模拟登录成功后
        userStore.setUserInfo({
            role: 'admin',
            token: 'demo-token'
        })
        router.push('/workbench')
    } catch (error) {
        // 错误处理
    }
}
</script>

<style lang="less" scoped>
.login-container {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: url('@/assets/img/login/background.jpg') no-repeat center center fixed;

    .login-box {
        width: 420px;
        padding: 40px 35px;
        border-radius: 12px;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
        border: none;

        .title {
            text-align: center;
            margin-bottom: 35px;
            color: #161616;
            font-size: 24px;
            letter-spacing: 2px;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        }

        :deep(.custom-input) {
            .el-input__wrapper {
                border-radius: 6px;
                padding: 4px 15px;
                transition: all 0.3s ease;

                &:hover {
                    box-shadow: 0 0 0 1px var(--el-input-hover-border-color) inset;
                }

                &.is-focus {
                    box-shadow: 0 0 0 2px var(--el-color-primary) inset;
                }
            }
        }

        .password-eye {
            cursor: pointer;
            padding: 0 5px;
            transition: color 0.3s;

            &:hover {
                color: var(--el-color-primary) !important;
            }
        }

        .login-btn {
            width: 100%;
            margin-top: 25px;
            height: 42px;
            font-size: 16px;
            letter-spacing: 2px;
            background: linear-gradient(45deg, #409eff, #3375b9);
            border: none;
            transition: all 0.3s;

            &:hover {
                opacity: 0.9;
                transform: translateY(-1px);
            }

            &:active {
                transform: translateY(0);
            }
        }
    }
}
</style>